package summary;

import java.util.Arrays;
import java.util.PriorityQueue;

/**
 * @Author: 海琳琦
 * @Date: 2022/6/9 10:18
 * https://leetcode.cn/problems/find-subsequence-of-length-k-with-the-largest-sum/
 */
public class Title2099 {

    public int[] maxSubsequence(int[] nums, int k) {
        PriorityQueue<int[]> queue = new PriorityQueue<>((a, b) -> (b[0] - a[0]));
        for (int i = 0; i < nums.length; i++) {
            queue.offer(new int[]{nums[i], i});
        }
        int[] index = new int[k];
        for (int i = 0; i < k; i++) {
            index[i] = (queue.poll())[1];
        }
        Arrays.sort(index);
        int[] result = new int[k];
        for (int i = 0; i < k; i++) {
            result[i] = nums[index[i]];
        }
        return result;
    }

    public static void main(String[] args) {

    }
}
